<%@page import="java.awt.PageAttributes"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import="util.DomainUtils"%>
<%@ page import="domain.entities.interfaces.*"%>
<%@ page import="domain.dao.interfaces.*"%>
<%@ page import="org.springframework.context.ApplicationContext"%>
<%@ page import="org.springframework.context.support.ClassPathXmlApplicationContext"%>
<%@ taglib prefix="html" uri="http://struts.apache.org/tags-html"%>
<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean"%>
<%@ taglib prefix="nested" uri="http://struts.apache.org/tags-nested"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Add contact</title>
<link rel="stylesheet" type="text/css" href="/mdoc-project/css/bootstrap_Boris.css">
<base href="<%=request.getScheme()%>://<%=request.getServerName()%>:<%=request.getServerPort()%><%=request.getContextPath()%>/">
</head>
<body>

	<%
		boolean connected = session
				.getAttribute(DomainUtils.CURRENT_USER_STRING) != null;

		if (connected == false) {
			request.setAttribute(DomainUtils.ALERT_ERROR_STRING,
					"You must be connected");
		}
	%>

	<%@include file="/pages/common_style/header.jsp"%>
	<%@include file="/pages/common_style/alerts.jsp"%>

	<%
		if (connected) {
	%>
	<html:errors />
	<html:form action="/AddContact">

		<br>
		<div class="form-group">
			<label for="firstname">First name</label>
			<input type="text" class="form-control" id="firstname" value="<%=DomainUtils
							.getNotNullValue(request, "first_name")%>" placeholder="Enter a first name" name="first_name">
			<label for="lastname">Last name</label>
			<input type="text" class="form-control" id="lastname" value="<%=DomainUtils.getNotNullValue(request, "last_name")%>" placeholder="Enter a last name" name="last_name">
			<label for="email">E-mail</label>
			<input type="email" class="form-control" id="email" value="<%=DomainUtils.getNotNullValue(request, "e_mail")%>" placeholder="Enter an e-mail adress" name="e_mail">
			<label for="street">Street</label>
			<input type="text" class="form-control" id="street" value="<%=DomainUtils.getNotNullValue(request, "street")%>" placeholder="Enter a street number and street name " name="street">
			<label for="city">City</label>
			<input type="text" class="form-control" id="city" value="<%=DomainUtils.getNotNullValue(request, "city")%>" placeholder="Enter a city's name" name="city">
			<label for="zip">Zip code</label>
			<input type="text" class="form-control" id="zip" value="<%=DomainUtils.getNotNullValue(request, "zip")%>" placeholder="Enter a zip code " name="zip">
			<label for="country">Country</label>
			<input type="text" class="form-control" id="country" value="<%=DomainUtils.getNotNullValue(request, "country")%>" placeholder="Enter a country name " name="country">
			<label for="mobile">Mobile</label>
			<input type="text" class="form-control" id="mobile" value="<%=DomainUtils.getNotNullValue(request, "mobile")%>" placeholder="Enter a phone number" name="mobile">
			<label for="house">House</label>
			<input type="text" class="form-control" id="house" value="<%=DomainUtils.getNotNullValue(request, "house")%>" placeholder="Enter a phone number" name="house">
			<label for="work">Work</label>
			<input type="text" class="form-control" id="work" value="<%=DomainUtils.getNotNullValue(request, "work")%>" placeholder="Enter a phone number " name="work">
			<label for="contactgroups">Select groups that will contains this contact</label>
			<div class="form-control" id="contactgroups_div" name="contactgroups_div" style="overflow: scroll; height: 150px;">
				<%
					ApplicationContext context = util.SpringUtils
									.getApplicationContext();
							String options = "";
							IUser user = (IUser) request.getSession(false)
									.getAttribute(DomainUtils.CURRENT_USER_STRING);

							// 					for (ContactGroup cg : DAOFactory.getDaoContactGroup().getByUserId(
							// 							user.getId())) {
							IDAOContactGroup daoContactGroup = (IDAOContactGroup) context
									.getBean("beanDAOContactGroup");
							for (IContactGroup cg : daoContactGroup.getByUserId(user
									.getId())) {
								options += "<input type=\"checkbox\" name=\"contactgroups\" id=\"chbx_"
										+ cg.getGroupId()
										+ "\" value=\""
										+ cg.getGroupId()
										+ "\"/>"
										+ "<label for=\"chbx_"
										+ cg.getGroupId()
										+ "\">" + cg.getGroupName() + "</label><br>";
							}
				%>
				<%=options%>
			</div>
			<br>
			Complementary informations for enterprise :
			<br>
			<label for="numsiret">Num Siret</label>
			<input type="text" class="form-control" id="numsiret" value="<%=DomainUtils.getNotNullValue(request, "num_siret")%>" placeholder="Enter a siret number" name="num_siret">
			<br>
			<button type="submit" class="btn btn-default">Submit</button>
			<button type="reset" class="btn btn-default">Reset</button>
		</div>
	</html:form>
	<%
		}
	%>
	<%@include file="/pages/common_style/footer.jsp"%>
	</div>
</body>
</html>